// ml278
// Copyright (C) 2008 Bjørn Øivind Bjørnsen, Aleksander Gjermundsen, Knut Andre Tidemann, Thomas Hansen
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

uniform sampler2D sLookup;
uniform sampler2D sGroundPack;

varying float fAlt;
varying float fSlope;

void main()
{
   // TODO: fBm noise texture
   //float slope = fSlope + (noise1(fSlope) * 0.001);
   //float alt = fAlt + (noise1(fAlt) * 0.001);
   
   vec4 terrainType = texture2D(sLookup, vec2(fSlope, fAlt));
   // IDs now embedded in lut-table
   //int id0 = int(terrainType.x * 16.0);
   //vec2 offset0 = vec2(int(mod(float(id0), float(nbTiles))), id0 / nbTiles);
   vec2 offset0 = terrainType.yz;
   
   terrainType.x = terrainType.x * 16.0;
   terrainType.y = terrainType.y * 32.0;
   terrainType.z = terrainType.z * 32.0;
   vec4 diffuse = vec4(terrainType.x, terrainType.y, terrainType.z, 1.0);
   
   gl_FragColor = diffuse;
}
